/**
 * 等所有的异步任务都执行完再执行回调函数 callback
 * @param {*} times 异步任务执行个数
 * @param {*} callback 回调函数
 * @returns
 */
const runAllFn = (times, callback) => {
  let obj = {};
  return (key, value) => {
    obj[key] = value;
    if (--times == 0) {
      callback(obj);
      obj = {};
      console.log("所有的都执行完");
    }
  };
};

const out = runAllFn(2, (obj) => {
  console.log("data: ", obj);
});

setTimeout(() => {
  out("a", "aaaa");
}, 1000);
setTimeout(() => {
  out("b", "bbbb");
}, 4000);
